this.BX=this.BX||{};(function(e,t,n){"use strict";function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){babelHelpers.defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var a=true;var o=function(){function e(){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"cache",new t.Cache.MemoryCache)}babelHelpers.createClass(e,[{key:"getControllerUrl",value:function e(){var n=this;return this.cache.remember("controllerUrl",(function(){var e=new t.Uri("/bitrix/tools/landing/ajax.php");e.setQueryParams({site:t.Loc.getMessage("SITE_ID")||undefined,type:n.getSitesType()});return e.toString()}))}},{key:"getSiteId",value:function e(){return this.cache.remember("siteId",(function(){var e=t.Reflection.getClass("BX.Landing.Main");if(e){var n=e.getInstance();if("options"in n&&"site_id"in n.options&&!t.Type.isUndefined(n.options.site_id)){return n.options.site_id}}return-1}))}},{key:"getLandingId",value:function e(){return this.cache.remember("landingId",(function(){var e=t.Reflection.getClass("BX.Landing.Main");if(e){return e.getInstance().id}return-1}))}},{key:"getSitesType",value:function e(){return this.cache.remember("siteType",(function(){return n.Env.getInstance().getType()}))}},{key:"action",value:function n(i){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var o=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};var c=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};if(!o.site_id){o.site_id=this.getSiteId()}var s={sessid:t.Loc.getMessage("bitrix_sessid"),action:c.action||i.replace("Landing\\Block","Block"),data:r(r({},a),{},{uploadParams:c,lid:a.lid||this.getLandingId()})};var u=new t.Uri(this.getControllerUrl());u.setQueryParams(r({action:s.action},o));return e.request({url:u.toString(),data:s}).then((function(e){if(s.action==="Block::updateNodes"||s.action==="Block::removeCard"||s.action==="Block::cloneCard"||s.action==="Block::addCard"||s.action==="Block::updateStyles"){BX.Landing.UI.Panel.StatusPanel.getInstance().update()}BX.onCustomEvent(BX.Landing.PageObject.getRootWindow(),"BX.Landing.Backend:action",[i,a]);return e.result}))["catch"]((function(e){if(s.action!=="Landing::downBlock"&&s.action!=="Landing::upBlock"){if(s.action!=="Block::getById"&&s.action!=="Block::publication"&&s.action!=="Landing::move"&&s.action!=="Landing::copy"&&s.action!=="Landing::publication"&&s.action!=="Site::publication"&&s.action!=="Site::moveFolder"&&s.action!=="Site::markDelete"&&s.action!=="Vk::getVideoInfo"){var n=t.Type.isString(e)?{type:"error"}:e;e.action=s.action;BX.Landing.ErrorManager.getInstance().add(n)}return Promise.reject(e)}}))}},{key:"batch",value:function n(i){var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var o=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};o.site_id=this.getSiteId();var c={sessid:t.Loc.getMessage("bitrix_sessid"),action:i.replace("Landing\\Block","Block"),data:{lid:a.lid||this.getLandingId()},batch:a};var s=new t.Uri(this.getControllerUrl());s.setQueryParams(r({action:c.action},o));return e.request({url:s.toString(),data:c}).then((function(e){BX.Landing.UI.Panel.StatusPanel.getInstance().update();BX.onCustomEvent(BX.Landing.PageObject.getRootWindow(),"BX.Landing.Backend:batch",[i,a]);return e}))["catch"]((function(e){if(c.action!=="Landing::downBlock"&&c.action!=="Landing::upBlock"){if(c.action!=="Block::getById"){var n=t.Type.isString(e)?{type:"error"}:e;n.action=c.action;BX.Landing.ErrorManager.getInstance().add(n)}return Promise.reject(e)}}))}},{key:"upload",value:function n(i){var r=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var a=new FormData;a.append("sessid",t.Loc.getMessage("bitrix_sessid"));a.append("picture",i,i.name);if("block"in r){a.append("action","Block::uploadFile");a.append("data[block]",r.block)}if("lid"in r){a.set("action","Landing::uploadFile");a.append("data[lid]",r.lid)}if("id"in r){a.set("action","Site::uploadFile");a.append("data[id]",r.id)}if("temp"in r){a.append("data[temp]",true)}var o=new t.Uri(this.getControllerUrl());o.setQueryParams({action:a.get("action"),site_id:this.getSiteId()});if(r.context){o.setQueryParam("context",r.context)}return e.request({url:o.toString(),data:a}).then((function(e){return e.result}))["catch"]((function(e){var n=t.Type.isString(e)?{type:"error"}:e;n.action="Block::uploadFile";BX.Landing.ErrorManager.getInstance().add(n);return Promise.reject(e)}))}},{key:"getSites",value:function e(){var t=this;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},i=n.filter,r=i===void 0?{}:i;return this.cache.remember("sites+".concat(JSON.stringify(r)),(function(){return t.action("Site::getList",{params:{filter:r,order:{ID:"DESC"}}}).then((function(e){return e}))}))}},{key:"getLandings",value:function e(){var n=this;var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},r=i.siteId,a=r===void 0?[]:r;var o=arguments.length>1?arguments[1]:undefined;var c=false;if(!BX.Type.isPlainObject(o)){o={};c=true}var s=t.Type.isArray(a)?a:[a];o.SITE_ID=s;var u=function e(t){return{action:"Landing::getList",data:{params:{filter:function(){if(c){return{SITE_ID:t,DELETED:"N",FOLDER:"N"}}return o}(),order:{ID:"DESC"},get_preview:true,check_area:1}}}};var d=function e(t){return t.reduce((function(e,t){return[].concat(babelHelpers.toConsumableArray(e),babelHelpers.toConsumableArray(t.result))}),[])};return this.cache.remember("landings+".concat(JSON.stringify(s)),(function(){if(s.filter((function(e){return!t.Type.isNil(e)})).length===0){return n.getSites().then((function(e){var t=e.map((function(e){return u(e.ID)}));return n.batch("Landing::getList",t)})).then((function(e){return d(e)})).then((function(e){e.forEach((function(e){n.cache.set("landing+".concat(e.ID),Promise.resolve(e))}))}))}var e=s.map((function(e){return u(e)}));return n.batch("Landing::getList",e).then((function(e){return d(e)})).then((function(e){e.forEach((function(e){n.cache.set("landing+".concat(e.ID),Promise.resolve(e))}));return e}))}))}},{key:"getLanding",value:function e(n){var i=this;var r=n.landingId;return this.cache.remember("landing+".concat(r),(function(){return i.action("Landing::getList",{params:{filter:{ID:r},get_preview:true}}).then((function(e){if(t.Type.isArray(e)&&e.length>0){return e[0]}return null}))}))}},{key:"getBlocks",value:function e(t){var n=this;var i=t.landingId;return this.cache.remember("blocks+".concat(i),(function(){return n.action("Block::getList",{lid:i,params:{get_content:true,edit_mode:true}}).then((function(e){e.forEach((function(e){n.cache.set("block+".concat(e.id),Promise.resolve(e))}));return e}))}))}},{key:"getBlock",value:function e(t){var n=this;var i=t.blockId;return this.cache.remember("blockId+".concat(i),(function(){return n.action("Block::getById",{block:i,params:{edit_mode:true}})}))}},{key:"getTemplates",value:function e(){var t=this;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},i=n.type,r=i===void 0?"page":i,a=n.filter,o=a===void 0?{}:a;return this.cache.remember("templates+".concat(JSON.stringify(o)),(function(){return t.action("Demos::getPageList",{type:r,filter:o}).then((function(e){return Object.values(e)}))}))}},{key:"getDynamicTemplates",value:function e(){var t=this;var n=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";return this.cache.remember("dynamicTemplates:".concat(n),(function(){return t.getTemplates({filter:{section:"dynamic".concat(n?":".concat(n):"")}})}))}},{key:"createPage",value:function e(){var i=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var r=n.Env.getInstance().getOptions();var a=i.title,o=i.siteId,c=o===void 0?r.site_id:o,s=i.siteType,u=s===void 0?r.params.type:s,d=i.code,l=d===void 0?t.Text.getRandom(16):d,g=i.blockId,f=i.menuCode,p=i.folderId;var h=function(){var e=r.theme;if(t.Type.isPlainObject(e)&&t.Type.isArray(e.newPageTemplate)&&t.Type.isStringFilled(e.newPageTemplate[0])){return e.newPageTemplate[0]}return"empty"}();var v={siteId:c,code:h,fields:{TITLE:a,CODE:l,ADD_IN_MENU:u==="KNOWLEDGE"||u==="GROUP"?"Y":"N"}};if(t.Type.isNumber(g)&&t.Type.isString(f)){v.fields.BLOCK_ID=g;v.fields.MENU_CODE=f}if(t.Type.isNumber(p)){v.fields.FOLDER_ID=p}return this.action("Landing::addByTemplate",v)}}],[{key:"getInstance",value:function t(){if(!e.instance){e.instance=new e}return e.instance}},{key:"makeResponse",value:function e(n){var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var a=function(){if(t.Type.isStringFilled(i.type)){return i.type}if(t.Type.isPlainObject(i)&&Object.values(i).length>0){var e=Object.values(i).every((function(e){return e.type==="success"}));if(e){return"success"}}if(t.Type.isArray(i)){return"other"}return"error"}();if(a==="other"){return i}return r(r({result:null,type:a},i),{},{status:n.status,authorized:n.getResponseHeader("X-Bitrix-Ajax-Status")!=="Authorize"})}},{key:"request",value:function n(i){var o=i.url,c=i.data;return new Promise((function(n,i){var s=c instanceof FormData?c:t.Http.Data.convertObjectToFormData(c);var u=t.ajax({method:"POST",dataType:"json",url:o,data:s,start:false,preparePost:false,onsuccess:function s(d){var l=e.makeResponse(u,d);if(t.Type.isStringFilled(l.sessid)&&t.Loc.getMessage("bitrix_sessid")!==l.sessid&&a){t.Loc.setMessage("bitrix_sessid",l.sessid);a=false;var g=r(r({},c),{},{sessid:t.Loc.getMessage("bitrix_sessid")});e.request({url:o,data:g}).then((function(e){a=true;n(e)}))["catch"]((function(e){a=true;i(e)}));return}if(!t.Type.isPlainObject(l)){n(l);return}if(l.type==="error"||l.authorized===false){if(l.authorized===false){top.window.location.reload()}else{i(l)}return}n(l)},onfailure:function t(n){if(n==="auth"){top.window.location.reload()}else{i(e.makeResponse(u,n))}}});u.send(s)}))}}]);return e}();babelHelpers.defineProperty(o,"instance",null);e.Backend=o})(this.BX.Landing=this.BX.Landing||{},BX,BX.Landing);
//# sourceMappingURL=backend.bundle.map.js